<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--<link href="../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">-->
		<link rel="stylesheet" type="text/css" href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />-->
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/commodity_details.css" />
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			.shenglue{
				overflow: hidden;
				text-overflow:ellipsis;
				white-space: nowrap;
			}
		</style>
	</head>

	<body>
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="javascript:history.go(-1)"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">商家详情页</p>
					<a id="headerPay" onclick="pay()"></a>
				</div>
				<div id="content">
					<div class="seller_wap">
						<div class="pic">
							<img id="shopDetailsPic" src="" />
							<p  style="padding-left: 10%;padding-right: 10%;" class="shenglue"  id="sign"></p>
						</div>
						<div style="background-color: #FFF; padding: 10px 0;">
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="shopName"><b>店名：</b><span></span>
								<a id="shouchang" style="position: absolute;right: 0; margin-top: 0.069444rem;margin-right: 0.277777rem;">收藏 
									<img src="../../../images/coalltion/weishouchang.png" style="width: 0.5rem; position: relative;top: -1px;" alt="" />
								</a>
							</p>
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" class="shenglue" id="acticeName"><b>活动名称：</b><span></span></p>
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="add"><b>所在区域/地址：</b><span></span></p>
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="shopTel"><b>电话: </b><span></span></p>
							<!--<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="time"><b>活动时间：</b><span></span></p>-->
						</div>
						<h1 style="position: relative;">
							用户评价(<span id="assess">0</span>)  
						
						</h1>

					</div>
				</div>
			</div>
			<div id="foot" class="row">
				<a class="foot col-xs-3 col-sm-3" href="../../kaoqin/index2.html">
					<img class="footImg" src="../../../images/15.png" />
					<p>管理</p>
				</a>
				<a class="foot col-xs-3 col-sm-3" href="../colalition.html">
					<img class="footImg" src="../../../images/14.png" />
					<p>联盟</p>
				</a>
				<a class="foot col-xs-3 col-sm-3" href="../../store/store.html">
					<img class="footImg" src="../../../images/11.png" />
					<p>商城</p>
				</a>
				<a class="foot col-xs-3 col-sm-3" href="../../personage/personIndex.html">
					<img class="footImg" src="../../../images/13.png" />
					<p>我的</p>
				</a>
			</div>
		</div>

	</body>
	<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/handlebars-v2.0.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/rhAdmin.js" type="text/javascript" charset="utf-8"></script>
	<script id="table_template1" type="text/x-handlebars-template">
		{{#each list}}
		<div class="pingjia">
			<img src="../../../images/coalltion/touxiang.png" />
			<p>{{memberName}}</p>
			<span>{{assessDate}}</span>
		</div>
		<div class="pingjia_main">
			{{assessContent}}
		</div>
		{{/each}}
	</script>
	<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var shopId = "";
		$(function() {
			var saId = getQueryString("saId");
			var shopId = saId;
			console.log(shopId);
			if(!$.cookie('tokenRh')){
				al("您还未登录，请登录后再试");
			}
			$.ajax({
				url: "http://47.104.13.109/mall-service/saapply/search",
				type: "GET",
				data: {
					saId: saId
				},
				success: function(data) {
					console.log(data);
					var saId = data.saId;
					$("#shopDetailsPic").attr('src', data.saPicture);
					document.getElementById('sign').innerHTML = data.saContent;
					$("#shopName span").html(data.siName);
					$("#acticeName span").html(data.saContent);
					$("#add span").html(data.saCityName + "/" + data.saAreaName);
//					$("#shopTel a").html("接口暂时没有电话");
					$("#time span").html(data.saBeginDate + "--" + data.saEndDate);
				},
				error: function(e) {
					console.log('根据saId获取活动详情出错', e)
				}
			});

			// 获取活动列表页面传递过来的参数
			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			}
			//判断商户是否收藏
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/member-service/member/client/collect/check",
				async: true,
				data: {
					shop_id: shopId,
					token: $.cookie("tokenRh")
				},
				success: function(res1) {
					if(res1) {
						$("#shouchang img").attr('src', '../../../images/coalltion/shouchang.png');
					}
				}
			});

			//获取商户的评价列表
			$.ajax({
				type: "GET",
				url: "http://47.104.13.109/mall-service/assess/list",
				async: true,
				data: {
					//					"goodsId":null,
					"shopId": shopId,
					"pageNum": "1",
					"pageSize": "10"
				},
				success: function(data) {
					document.getElementById('assess').innerHTML = data.size;
					//					console.log(data);
					var myTemplate1 = Handlebars.compile($("#table_template1").html());
					$('.seller_wap').append(myTemplate1(data));
				}
			});
		})

		function pay() {
			//登陆判断
			var tokenRezt = $.cookie("tokenRezt");
			if(!tokenRezt) {
				window.location.href = "../../login/login/login2.html";
				return
			}
			if(shopId != "") {
				window.location.href = "../commodity_pay/foods_pay.html?shopId=" + shopId;
			}

		}
		//查询是否收藏
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/member-service/member/client/collect/check",
			async: true,
			data: {
				shop_id: shopId,
				token: $.cookie('tokenRh')
			},
			success: function(bol) {
				if(bol) {
					$("#shouchang img").attr('src', '../../../images/coalltion/shouchang.png');
				} else {
					$("#shouchang img").attr('src', '../../../images/coalltion/weishouchang.png');
				}
			},
			error: function(error) {
				alert("出现错误，请联系系统管理员");
			}
		});
		$("#shouchang").click(function() {
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/member-service/member/client/collect/check",
				async: true,
				data: {
					shop_id: shopId,
					token: $.cookie('tokenRh')
				},
				success: function(bol) {
					if(bol) {
						//删除收藏
						$.ajax({
							type: "delete",
							url: 'http://47.104.13.109/member-service/member/mine/collect/' + shopId + '?token=' + $.cookie("tokenRh"),
							async: true,
							success: function(res) {
								console.log(res);
								if(res) {
									$("#shouchang img").attr('src', '../../../images/coalltion/weishouchang.png');
								}
							},
							error: function(error) {
								alert("出现错误，请联系系统管理员");
							}
						});
					} else {
						//添加收藏
						$.ajax({
							type: "post",
							url: 'http://47.104.13.109/member-service/member/mine/collect/' + shopId + '?token=' + $.cookie("tokenRh"),
							async: true,
							success: function(res1) {
								console.log(res1);
								if(res1) {
									$("#shouchang img").attr('src', '../../../images/coalltion/shouchang.png');
								}
							},
							error: function(error) {
								alert("出现错误，请联系系统管理员");
							}
						});
					}
				},
				error: function(error) {
					alert("出现错误，请联系系统管理员");
				}
			});

		})
	</script>

</html>